var mainFilter = angular.module('mainFilter', []);
//城市字母排序
mainFilter.filter('filtrateSort', function() {
	 return function(obj,newNum){
	 	var newObj = [];
	 	angular.forEach(obj, function (o) {
            if (o.sort == newNum) {
                newObj.push(o);
            }
        });
        return newObj;
	 }
});
//字符串转数字
mainFilter.filter('strTranformNum',function(){
	return function(str){
		var str = Number(str);
		var num = Math.round(str*10)/10;
		if(num%1 === 0){
			num = num.toString() + '.0';
		}
		return num;
	}
});
//评分小数处理
mainFilter.filter('gradeNum',function(){
	return function(str){
		var str = str;
		if(str == undefined){
			str = 0;
		}
		str = str.toString();	
		var array = str.split(".");
		if(array[1]!==undefined||array[1]!==null||array[1]!==""){
			var num = Number('0.' + array[1]);
			if(num <= 0.5&&num!==0){
				str = array[0] + '.5';
			}else if(num > 0.5){
				str = Math.round(Number(str));			
			}
		}
		return str;	
	}	
})
//定义充电类型
var chargerTypeArray = {};
chargerTypeArray['1'] = '直流 快充';
chargerTypeArray['2'] = '交流220V  慢充';
chargerTypeArray['3'] = '混合';

//定义充电桩状态
var chargerStatusArray = {};
chargerStatusArray['0'] = '空闲中';
chargerStatusArray['1'] = '预约中';
chargerStatusArray['2'] = '充电中';
chargerStatusArray['3'] = '故障中';
chargerStatusArray['4'] = '占用中';
chargerStatusArray['5'] = '刷卡中';
chargerStatusArray['8'] = '离线中';

//定义站点交流慢充是否空闲
var isACFreeArray = {};
isACFreeArray['0'] = '有空闲';
isACFreeArray['1'] = '无空闲';

//定义站点直流是否空闲
var isDCFreeArray = {};
isDCFreeArray['0'] = '有空闲';
isDCFreeArray['1'] = '无空闲';

/**
 * 根据本地定义的map和传入input返回对应的value
 */
mainFilter.filter('getValueInStaticFilter', function() {
	return function(input, staticArrayName) {
		var value = eval(staticArrayName + "[input]");
		if (!!value) {
			return value;
		}
		return "";
	};
});